#ifndef SYMBOLTABLE_H
#define SYMBOLTABLE_H

#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define INTEGER_SIZE 4
#define REAL_SIZE 8
#define BOOLEAN_SIZE 1
#define CHAR_SIZE 2

#define INTEGER 1
#define REAL 2
#define BOOLEAN 3
#define CHAR 4
#define ARRAY 5
#define FUNCTION 6
#define PROCEDURE 7

class SymbolTableNode
{
public:
    string Name;        // variable name
    int Memloc;         // memory location
    vector<int> Type;   // basic type
    vector<int> Lines;  // where a variable occurs
    vector<int> Degree; // if the type is function, it's types of variable. If the type is array,it's the range of array

    SymbolTableNode(string name, vector<int> type, vector<int> lines, vector<int> degreee);
    void getInfo();
};

SymbolTableNode::SymbolTableNode(string name, vector<int> type, vector<int> lines, vector<int> degreee)
{
    Name = name;
    Type = type;
    Lines = lines;
    Degree = degreee;
}

void SymbolTableNode::getInfo()
{
    cout << "name: " << Name << endl;
    cout << "type: ";
    for (vector<int>::iterator it = Type.begin(); it != Type.end(); it++)
    {
        switch (*it)
        {
        case INTEGER:
            cout << "INTEGER	";
            break;
        case REAL:
            cout << "REAL	";
            break;
        case BOOLEAN:
            cout << "BOOLEAN	";
            break;
        case CHAR:
            cout << "CAHR	";
            break;
        case ARRAY:
            cout << "ARRAY	";
            break;
        case FUNCTION:
            cout << "FUNCTION	";
            break;
        case PROCEDURE:
            cout << "PROCEDURE	";
            break;
        default:
            cout << "出现类型错误" << endl;
            break;
        }
    }
    cout << endl
         << "memory location: " << Memloc << endl;
    cout << "lines: ";
    for (vector<int>::iterator it = Lines.begin(); it != Lines.end(); it++)
    {
        cout << *it << "   ";
    }
    cout << endl;
    if (Type[0] == ARRAY)
    {
        cout << "the size of array: ";
        for (vector<int>::iterator it = Degree.begin(); it != Degree.end(); it++)
        {
            cout << *it << "   ";
        }
    }
    else if (Type[0] == FUNCTION || Type[0] == PROCEDURE)
    {
        cout << "the types of function/procedure: ";
        for (vector<int>::iterator it = Degree.begin(); it != Degree.end(); it++)
        {
            switch (*it)
            {
            case INTEGER:
                cout << "INTEGER	";
                break;
            case REAL:
                cout << "REAL	";
                break;
            case BOOLEAN:
                cout << "BOOLEAN	";
                break;
            case CHAR:
                cout << "CAHR	";
                break;
            case ARRAY:
                cout << "ARRAY	";
                break;
            case FUNCTION:
                cout << "FUNCTION	";
                break;
            case PROCEDURE:
                cout << "PROCEDURE	";
                break;
            default:
                cout << "出现类型错误" << endl;
                break;
            }
        }
    }
    cout << endl
         << endl;
}

#endif